#include<iostream>
#include<cstring>
using namespace std;
const int N = 1e5 + 10, M = N * 2;
int h[N], e[M], ne[M], w[M], idx;
int f[N], sz[N];
int ans = 1e9;
int n;
void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
void dfs(int u, int fa, int step)
{
	sz[u] = w[u];
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		if (j != fa) {
			dfs(j, u, step + 1);
			sz[u] += sz[j];
		}
	}
	f[1] += w[u] * step;
}
void dfs2(int u, int fa)
{
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		if (j != fa) {
			f[j] = f[u] - sz[j] + sz[1] - sz[j];
			dfs2(j, u);
		}
	}
	ans = min(f[u], ans);
}
int main()
{
	cin >> n;
	memset(h, -1, sizeof(h));
	for (int i = 1; i <= n; i++) {
		int a, b, c;
		cin >> c >> a >> b;
		w[i] = c;
		add(i, a);
		add(i, b);
	}
	dfs(1, 0, 0);
	//cout << f[1] << endl;
	/*for (int i = 1; i <= n; i++) {
		cout << "i==" << i << "  " << sz[i] << endl;
	}*/
	dfs2(1, 0);
	cout << ans << endl;
	return 0;
}